
<style scoped>
  .layout{
    border: 1px solid #d7dde4;
    background: #f5f7f9;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    height:100%;
    width: 100%;
  }
  .ivu-row-flex{
    height:100%;
  }
  .layout-breadcrumb{
    padding: 10px 15px 0;
  }
  .layout-content{
    min-height: 200px;
    margin: 15px;
    overflow: hidden;
    background: #fff;
    border-radius: 4px;
  }
  .layout-content-main{
    padding: 10px;
  }
  .layout-copy{
    text-align: center;
    padding: 10px 0 20px;
    color: #9ea7b4;
  }
  .layout-menu-left{
    background: #464c5b;
  }
  .layout-header{
    height: 60px;
    background: #fff;
    box-shadow: 0 1px 1px rgba(0,0,0,.1);
  }
  .layout-logo-left{
    width: 90%;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    margin: 15px auto;
  }
  .layout-ceiling-main a{
    color: #9ba7b5;
  }
  .layout-hide-text .layout-text{
    display: none;
  }
  .ivu-col{
    transition: width .2s ease-in-out;
  }
</style>
<style>
  html,body{
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    overflow: hidden;
  }
  .main{
    height: 100%;
    width: 100%;
  }
  .main .single-page{
    position: absolute;
    top: 100px;
    right: 0;
    bottom: 0;
    overflow: auto;
    background-color: #f0f0f0;
    z-index: 1;
  }
  .main .single-page .home-main{
    margin: 10px;
  }
</style>
<template>
  <div class="layout" :class="{'layout-hide-text': spanLeft < 5}">
    <Row type="flex">
      <i-col :span="spanLeft" class="layout-menu-left">
        <Menu ref="sideMenu" active-name="1" theme="dark" width="auto" @on-select="changeMenu">
          <div class="layout-logo-left"></div>
          <template v-for="item in menuList">
            <MenuItem v-if="item.children.length<=1" :name="item.children[0].name" :key="item.path">
              <Icon :type="item.icon" :size="iconSize" :key="item.path"></Icon>
              <span class="layout-text" :key="item.path">{{ item.title }}</span>
            </MenuItem>

            <Submenu v-if="item.children.length>1" :name="item.name" :key="item.path">
              <template slot="title">
                <Icon :type="item.icon" :size="iconSize"></Icon>
                <span class="layout-text">{{ item.title }}</span>
              </template>
              <template v-for="child in item.children">
                <MenuItem :name="child.name" :key="child.name">
                  <Icon :type="child.icon" :size="iconSize" :key="child.name"></Icon>
                  <span class="layout-text" :key="child.name">{{ child.title }}</span>
                </MenuItem>
              </template>
            </Submenu>
          </template>
        </Menu>
      </i-col>
      <i-col :span="spanRight">
        <div class="layout-header">
          <i-button type="text" @click="toggleClick">
            <Icon type="navicon" size="32"></Icon>
          </i-button>
        </div>
        <div class="layout-breadcrumb">
          <Breadcrumb>
            <Breadcrumb-item href="#">首页</Breadcrumb-item>
          </Breadcrumb>
        </div>
        <div class="single-page">
          <router-view/>
          <div class="layout-copy">
            2011-2016 &copy; TalkingData
          </div>
        </div>
      </i-col>
    </Row>
  </div>
</template>
<script>
  export default {
    data () {
    return {
      spanLeft: 5,
      spanRight: 19
    }
  },
  computed: {
    menuList () {
      return this.$store.state.menuList;
    },
    iconSize () {
      return this.spanLeft === 5 ? 14 : 24;
    }
  },
  methods: {
    toggleClick () {
      if (this.spanLeft === 5) {
        this.spanLeft = 2;
        this.spanRight = 22;
      } else {
        this.spanLeft = 5;
        this.spanRight = 19;
      }
    },
    changeMenu (active) {
      console.info(active);
      this.$router.push({
        name: active
      });
    }
  }
  }
</script>
